<?php
class User_IndexController extends Zend_Controller_Action
{
	private $model;
	private $auth;
	public function init()
	{
		$this->model = new User_Model_Basic();
		$this->auth = Zend_Auth::getInstance();
		$dirfile = $this->_request->getBaseUrl() . "/application/layouts/user";
		$dirlayout = APPLICATION_PATH . "/layouts/user";
		$this->view->imgs = $dirfile . "/images";	
		$this->view->headLink()->appendStylesheet($dirfile . '/css/style.css');
		$this->view->headScript()->appendFile($dirfile . '/js/jquery-1.7.2.min.js');
		$this->view->headScript()->appendFile($dirfile . '/js/dropdown.js');
		$this->view->headScript()->appendFile($dirfile . '/js/slidedown.js');
		$this->view->headScript()->appendFile($dirfile . '/js/delvideo.js');
		$option = array('layoutPath'=>$dirlayout,'layout'=>'index');
		Zend_Layout::startMvc($option);
	}
	public function indexAction()
	{
		$data = $this->model->getallvideo($this->auth->getIdentity()->id_user);
		$paging = Zend_Paginator::factory($data);
		$paging->setItemCountPerPage(2);
		$paging->setPageRange(2);
		$current = $this->_request->getParam('page',1);
		$paging->setCurrentPageNumber($current);
		$this->view->paging = $paging;
	}
	public function getsearchAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->disableLayout();
		$content = $this->_request->getParam('text-search');
		$session = new Zend_Session_Namespace('search');
		$session->content = $content;
		$this->_forward('search');
		
	}
	public function searchAction()
	{
		$session = new Zend_Session_Namespace('search');
		$content = $session->content;
		$data = $this->model->search($content);
		$paging = Zend_Paginator::factory($data);
		$paging->setItemCountPerPage(2);
		$paging->setPageRange(2);
		$current = $this->_request->getParam('page',1);
		$paging->setCurrentPageNumber($current);
		$this->view->pagingsearch = $paging;
	}
	 public function logoutAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->disableLayout();
		$auth = Zend_Auth::getInstance();
		$update = $this->model->status($auth->getIdentity()->id_user, 0);
		$auth->clearIdentity();
		$this->_redirect('/');
	} 
}